/*******************************************************************************
 * Copyright (c) Jerges A. Bello G. 2014. Reservado todos los derechos.
 ******************************************************************************/
package com.jabex.persistence.model;


import com.jabex.common.to.ProductTO;
import org.joda.time.LocalTime;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import java.util.Date;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Jerges Bello
 * Date: 5/11/13
 * Time: 22:21
 * To change this template use File | Settings | File Templates.
 */

@Entity
@Table(name = "ADA_PRODUCT")
public class Product extends Identity {

	@Column(name = "NAME", unique = false, nullable = false)
	private String name;
	@Column(name = "DESCRIPTION", unique = false, nullable = false)
	private String description;
	@Column(name = "TYPE_PRODUCT", unique = false, nullable = false)
	private String typeProduct;
	@Column(name = "CREATE_DATE", unique = false, nullable = true)
	private Date createDate;
	@Column(name = "ACTIVE", unique = false, nullable = true)
	private Boolean isActive;
	@OneToMany(fetch = FetchType.LAZY)
	private List<Images> images;
	@ManyToMany(fetch = FetchType.LAZY)
	private List<Prices> prices;

	public Product() {
	}

	public Product(ProductTO productTO) {
		this.name = productTO.getName();
		this.description = productTO.getName();
		this.typeProduct = productTO.getTypeProduct();
		this.createDate = productTO.getCreateDate().toDate();
		if (productTO.getCreateTime() != null) {
			this.createDate.setTime(productTO.getCreateTime().toDateTime().getMillis());
		} else {
			this.createDate.setTime(productTO.getCreateDate().toDateTime(LocalTime.now()).getMillis());
		}
		this.isActive = productTO.getIsActive();
	}


	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}


	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}


	public String getTypeProduct() {
		return typeProduct;
	}

	public void setTypeProduct(String typeProduct) {
		this.typeProduct = typeProduct;
	}


	public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	public Boolean getIsActive() {
		return isActive;
	}

	public void setIsActive(Boolean isActive) {
		this.isActive = isActive;
	}

	public List<Prices> getPrices() {
		return prices;
	}

	public void setPrices(List<Prices> prices) {
		this.prices = prices;
	}

	public List<Images> getImages() {
		return images;
	}

	public void setImages(List<Images> images) {
		this.images = images;
	}
}
